package cn.lx.controller;


import cn.lx.entity.User;
import cn.lx.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.cache.CacheManager;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@RestController
public class UserController {

    @Autowired
    private UserService userService;

    @Autowired
    CacheManager cacheManager;

    @GetMapping("/users")
    public List<User> getUsers() {
        return userService.getUsers();
    }

    @GetMapping("/adduser")
    public Integer addSser() {
        User user = new User();
        user.setUserId(4);
        user.setUserName("赵四");
        user.setUserAge(38);
        return userService.addUser(user);
    }


    @GetMapping("/edituser")
    public Integer editUser() {
        User user = new User();
        user.setUserId(1);
        user.setUserName("ffff");
        user.setUserAge(30);
        userService.editUser(user);
        return null;
    }

    @RequestMapping(value = "/getusersbyname", method = RequestMethod.POST)
    public User geUsersByName1(@RequestBody User user) {
        System.out.println("-------------------------------------------");
        System.out.println("call /getusersbyname");
        System.out.println(cacheManager.toString());
        return userService.getUsersByName(user.getUserName());
    }


}
